package top.resty.erp.dao;

import org.apache.ibatis.annotations.*;
import top.resty.erp.commont.VOBrandAndVariety;
import top.resty.erp.domain.Variety;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年03月22 11:54
 */
@Mapper
public interface IVariety {
	
	
	@Insert("insert into tb_variety values (null,#{name},#{brandId})")
	public int saveVariety(Variety variety);
	
	
	@Select({"<script>" +
			"select t1.name as brandName , t2.id , t2.name as varietyName , t2.brand_id from tb_brand as t1 left join tb_variety as t2 on t1.id = t2.brand_id" +
			"<if test = 'id != 0'>" +
			"and t1.id = #{id}" +
			"</if>" +
			"</script>"})
	public List<VOBrandAndVariety> getBrandAndVarieties(@Param("id") Integer brandId);
	
	@Select("select id,name,brand_id as brandId from tb_variety where brand_id = #{brandId}")
	public List<Variety> getVarietyForBrandId(Integer brandId);
	
	
	
	@Delete("delete from tb_variety where id = #{id}")
	public int deleteVariety(Integer id);
	
	@Update("update tb_variety set name = #{name} where id = #{id}")
	public int updateVariety(Variety variety);
	
	@Select("select count(*) from tb_variety where brand_id = #{brandId};")
	public int queryBrandIdCountsForVarieties(Integer brandId);
	
}
